Setting materials for rendering

In Kanzi you can use these render passes to set materials for rendering:

Creating a night vision mode

You can use the Draw Objects With Material Render Pass to render all nodes under a Scene node with a specific material. For example, you can create a night vision mode.

To create a night vision mode:

  1. Create the content that you want to render in night vision mode.
    For example, use the Car from the Factory Content. See Using the Factory Content assets.
  2. Create and apply the render passes that you need to render the content in night vision mode:
    1. In the Library > Rendering press Alt and right-click Render Passes, select Group Render Pass, and name it Night Vision.
      You use this Group Render Pass to collect the render passes which apply the night vision mode to your content.
    2. In the Project select the Scene node the content of which you want to render in night vision mode, and in the Properties set the Render Pass property to the Night Vision render pass.
      This way you set Kanzi to render the Scene node using the Night Vision render pass. The Night Vision render pass does not have any child render passes, which is why the Preview does not show any content.
    3. In the Night Vision render pass create:
      1. Clear Render Pass
      2. Draw Objects With Material Render Pass
      You can use a Draw Objects With Material Render Pass render pass to render all nodes under a Scene node with a specific material that you set in the Draw Objects With Material Render Pass.
      Because you have not yet set the Material property in the Draw Objects With Material Render Pass, Kanzi uses the default materials to render the content in the Scene node which uses the Night Vision render pass.
  3. Create the material that you want to use for the night vision mode.
    For example, in the Library > Materials and Textures > Material Types press Alt and right-click VertexPhong, select Material, and name the material Night Vision Material.
    This way you create a material which uses the VertexPhong material type.
  4. In the Library > Rendering > Render Passes select the Draw Objects With Material Render Pass and in the Properties set the Material property to the material you created in the previous step.
    Kanzi now renders all nodes in the Scene node, which uses the Night Vision render pass, with the material that you created.

  5. In the Properties click the next to the Material property to open the properties of the material that you created, and set the properties of the material to achieve the look you want.

  6. In the Library > Rendering > Render Passes select the Clear Render Pass, in the Properties add the Clear Color property, and set the Lightness (L) property field to 0.
    This way you clear the color buffer with black color to make the background of your scene black in the night vision mode.
  7. Control the switching between the day and night vision modes.
    For example, create a State Manager where you define states for:

    See Creating a state manager.

    Now when you switch between the states you created, Kanzi alternates between rendering your content normally and in night vision mode.

Creating an infinity mirror

Material Setup Render Pass allows you to set properties for a material so that all successive rendering with that material uses the property values you set in this render pass. For example, you can use the Material Setup Render Pass to create an infinity mirror effect.

To create an infinity mirror:

  1. In the Project create:
  2. Create the material that you use to render the 3D content in the mirror:
    1. Create a textured material.
      For example, in the Library > Materials and Textures > Material Types press Alt and right-click Textured, select Material, and name the material Mirror Material.
    2. In the Project select the node that you want to use as the mirror and in the Properties set the Mesh Material property to the material you created in the previous step.
  3. Render the 3D content in the mirror:
    1. In the Library > Rendering press Alt and right-click Render Passes and select Group Render Pass.
      Group Render Pass allows you to collect render passes so that you can refer to a single render pass in your Scene or Viewport 2D node.
    2. In the Project select the Scene node the content of which you want to render in the mirror, and in the Properties set the Render Pass property to the Group Render Pass.
      This way you set Kanzi to render the Scene node using the Group Render Pass. The Group Render Pass does not have any child render passes, which is why the Preview does not show any content.
    3. In the Group Render Pass create a Composition Target Render Pass and inside that render pass create:
      1. Clear Render Pass
      2. Draw Objects Render Pass
      Kanzi now renders the Scene node to a composition target, which is why the Preview does not show any content.
    4. In the Group Render Pass create a Blit Render Pass, and in the Properties set the Texture0 property to the Composition Target Render Pass that you created in the previous step.
      You use this render pass to draw on the screen the Composition Target Render Pass which renders the content of the Scene node.
    5. In the Library select the Clear Render Pass and in the Properties add and set the Clear Color property.
      This way you clear the color buffer with the color you set in the Clear Color property and set the background color of the scene in the mirror.
    6. In the Library in the Group Render Pass create a second Composition Target Render Pass and drag the Blit Render Pass to that Composition Target Render Pass.
      You use the second Composition Target Render Pass to render the first Composition Target Render Pass to a composition target.
      You create two Composition Target Render Pass render passes because the rendering behavior is undefined if you simultaneously write to and read from the same render pass.

    7. In the Group Render Pass create a Default Render Pass.
      Default Render Pass creates a basic set of render passes that first render opaque nodes and then transparent nodes.
      You use this render pass to render to the screen the content of the Scene node.
    8. In the Group Render Pass create a Material Setup Render Pass and in the Properties add and set:
      • Material to the material that you created in step 2 of this procedure.
        For example, set it to Mirror Material.
      • Texture to the second Composition Target Render Pass that you created.
        For example, set it to Composition Target Render Pass 2.
        Here you set the value of the Texture property for the material that you created, so that Kanzi uses the value when rendering content using the Group Render Pass that you created.
      This way you set Kanzi to render the Composition Target Render Pass 2 in the node that uses the Mirror Material.

Kanzi now recursively renders the contents of the scene in the mirror.

See also

Rendering

Using materials